
****************************************************************************
*Table 1: Descriptive statistics of outcomes and demographic characteristics 
*         of low-educated migrants and urban resident in 1993 and 2015
***************************************************************************

version 15.1
cd "${mypath}\CHNS_project\01_data\02_posted\"

log using "${mypath}\CHNS_project\03_log_files\05_table_1.log", replace

use CHNS_1993_2015_20_imputed.dta,clear

*generate "over the statutory hours last week"
gen over_lastw = hours_lastw1 > 44 if employed_last1 == 1

*generate annual salary last year(log)
gen log_wage_i = log(exp(log_wage_1)*workmonths1+exp(log_bonuse_1)) if employed_last1 == 1

*generate hourly wage last year(log)
gen log_hour_wage = log_wage_1-log((365/12/7)*workdays1*workhours1) if employed_last1 == 1

*generate exclusion condition, that is, people who work in agriculture
gen be_farmer = (migrant_group != 2 & occupation == 3 & work_unit == 4) if be_employed == 1

local path "${mypath}\CHNS_project\04_tables\table_1\"

**1993
*migrant
misum be_employed year_education age gender ethnicity marital_status h_group1 h_group2 h_group3 h_group4 h_group5 num_child num_elderly if time != 1 & be_farmer != 1 & be_migrant == 1 & wave == 1993 & degree_education <= 3,matrix(migrant_1993_part1)
matrix migrant_1993_part1 = r(migrant_1993_part1)
putexcel set "`path'\migrant_1993_part1.xlsx", modify
putexcel A1 = matrix(migrant_1993_part1), names

misum workmonths1 hours_lastw1 over_lastw log_wage_i log_hour_wage if time != 1 & be_farmer != 1 & be_migrant == 1 & wave == 1993 & degree_education <= 3 & employed_last1 == 1,matrix(migrant_1993_part2)
matrix migrant_1993_part2 = r(migrant_1993_part2)
putexcel set "`path'\migrant_1993_part2.xlsx", modify
putexcel A1 = matrix(migrant_1993_part2), names

*urban resident
misum be_employed year_education age gender ethnicity marital_status h_group1 h_group2 h_group3 h_group4 h_group5 num_child num_elderly if time != 1 & be_farmer != 1 & be_urban_resident == 1 & wave == 1993 & degree_education <= 3,matrix(urban_1993_part1)
matrix urban_1993_part1 = r(urban_1993_part1)
putexcel set "`path'\urban_1993_part1.xlsx", modify
putexcel A1 = matrix(urban_1993_part1), names

misum workmonths1 hours_lastw1 over_lastw log_wage_i log_hour_wage if time != 1 & be_farmer != 1 & be_urban_resident == 1 & wave == 1993 & degree_education <= 3 & employed_last1 == 1,matrix(urban_1993_part2)
matrix urban_1993_part2 = r(urban_1993_part2)
putexcel set "`path'\urban_1993_part2.xlsx", modify
putexcel A1 = matrix(urban_1993_part2), names

**2015
*migrant
misum be_employed year_education age gender ethnicity marital_status h_group1 h_group2 h_group3 h_group4 h_group5 num_child num_elderly if time != 1 & be_farmer != 1 & be_migrant == 1 & wave == 2015 & degree_education <= 3,matrix(migrant_2015_part1)
matrix migrant_2015_part1 = r(migrant_2015_part1)
putexcel set "`path'\migrant_2015_part1.xlsx", modify
putexcel A1 = matrix(migrant_2015_part1), names

misum workmonths1 hours_lastw1 over_lastw log_wage_i log_hour_wage if time != 1 & be_farmer != 1 & be_migrant == 1 & wave == 2015 & degree_education <= 3 & employed_last1 == 1,matrix(migrant_2015_part2)
matrix migrant_2015_part2 = r(migrant_2015_part2)
putexcel set "`path'\migrant_2015_part2.xlsx", modify
putexcel A1 = matrix(migrant_2015_part2), names

*urban resident
misum be_employed year_education age gender ethnicity marital_status h_group1 h_group2 h_group3 h_group4 h_group5 num_child num_elderly if time != 1 & be_farmer != 1 & be_urban_resident == 1 & wave == 2015 & degree_education <= 3,matrix(urban_2015_part1)
matrix urban_2015_part1 = r(urban_2015_part1)
putexcel set "`path'\urban_2015_part1.xlsx", modify
putexcel A1 = matrix(urban_2015_part1), names

misum workmonths1 hours_lastw1 over_lastw log_wage_i log_hour_wage if time != 1 & be_farmer != 1 & be_urban_resident == 1 & wave == 2015 & degree_education <= 3 & employed_last1 == 1,matrix(urban_2015_part2)
matrix urban_2015_part2 = r(urban_2015_part2)
putexcel set "`path'\urban_2015_part2.xlsx", modify
putexcel A1 = matrix(urban_2015_part2), names

log close
